package mid

/*
* @author: hjz
* @time: 2025/6/4 22:11
* @desc:438. 找到字符串中所有字母异位词
	用数组模拟字符串
*/

func findAnagrams(s string, p string) []int {
	if len(p) > len(s) {
		return []int{}
	}
	pCount := [26]int{}
	window := [26]int{}
	for i := 0; i < len(p); i++ {
		pCount[p[i]-'a']++
	}
	l, r := 0, 0
	for r < len(p) {
		window[s[r]-'a']++
		r++
	}
	res := make([]int, 0, len(s)>>1)
	for r <= len(s) {
		if window == pCount {
			res = append(res, l)
		}
		if r == len(s) {
			break
		}
		window[s[l]-'a']--
		window[s[r]-'a']++
		l++
		r++
	}
	return res
}
